import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import Home from '../pages/home.vue';
import List from '../pages/list.vue';
import Cart from '../pages/cart.vue';
import Mine from '../pages/mine.vue';
import Is404 from '../pages/is404.vue'
import Detail from '../pages/detail.vue'
import Login from '../pages/login.vue'
import Reg from '../pages/reg.vue'

// import Cartc from '../components/cartc'
let router = new VueRouter({
    routes: [
        {
            name: 'login',
            path: '/login',
            component: Login
        },
        {
            name: 'reg',
            path: '/reg',
            component: Reg
        },
        {
            name: 'home',
            path: '/home',
            component: Home,
        },
        {
            path: '/',
            redirect: '/list',
        },
        {
            name: 'list',
            path: '/list',
            component: List,
        },
        {
            name: 'cart',
            path: '/cart',
            component: Cart,
            meta: {
                isenter: true
            }
        },
        {
            name: 'mine',
            path: '/mine',
            component: Mine,
            meta: {
                isenter: true
            }
        },
        {
            name: 'is404',
            path: '/is404',
            component: Is404,
        },
        {
            name: 'detail',
            path: '/detail',
            component: Detail,
        },

    ],

})
router.beforeEach(async (to, from, next) => {
    if (to.meta.isenter) {
        // 获取token
        let token = localStorage.getItem('token');
        // 向后端验证token
        
        if(token){
            router.
        }

    }else{

    }
})
// 导出路由
export default router;